package com.huike.clues.service.impl;


import com.huike.clues.domain.TbClue;
import com.huike.clues.domain.TbClueTrackRecord;
import com.huike.clues.domain.vo.ClueTrackRecordVo;
import com.huike.clues.mapper.TbClueMapper;
import com.huike.clues.mapper.TbClueTrackRecordMapper;
import com.huike.clues.service.ITbClueTrackRecordService;
import com.huike.common.core.page.TableDataInfo;
import com.huike.common.utils.SecurityUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * 线索跟进记录Service业务层处理
 * @date 2022-04-22
 */
@Service
public class TbClueTrackRecordServiceImpl implements ITbClueTrackRecordService {

    @Autowired
    TbClueTrackRecordMapper tbClueTrackRecordMapper;

    @Autowired
    TbClueMapper tbClueMapper;

    //查询线索跟进记录列表
    @Override
    public List<TbClueTrackRecord> listByCid(Long clueId) {

        return  tbClueTrackRecordMapper.listByCid(clueId);
    }

    //新增线索跟进记录
    @Override
    @Transactional
    public void add(ClueTrackRecordVo tbClueTrackRecord) {
        String username = SecurityUtils.getUsername();//获得当前用户
        TbClue tbClue = new TbClue();
        //拷贝数据到 线索表中
        BeanUtils.copyProperties(tbClueTrackRecord,tbClue);
        tbClue.setCreateTime(new Date());
        tbClue.setCreateBy(username);
        tbClue.setId(tbClueTrackRecord.getClueId());
        tbClueMapper.updateTbClue(tbClue);
        //拷贝到线索跟进线索表 ，设置状态 type 为 正在更近中
        TbClueTrackRecord trackRecord = new TbClueTrackRecord();
        BeanUtils.copyProperties(tbClueTrackRecord,trackRecord);
        trackRecord.setType("0");
        trackRecord.setCreateBy(username);
        tbClueTrackRecordMapper.add(trackRecord);

    }
}
